<script type="text/javascript" src="/modules/section_header/section_header.js">
</script>
<script type="text/javascript" src="/modules/image_rotator/image_rotator.js"></script>
<script  type="text/javascript">
add_css("/modules/section_header/css/section_header.css");
var m = 6000
var _section_header = new section_header ();    
var _image_rotator = new image_rotator("",m);   
</script>

<?php if (! isset($_SESSION["username"])) { ?>

<script type="text/javascript">



/*
Firefox has a bug that causes animations to queue. Therefore disable animations on blur and enable on focus.
*/
/*
jQuery(window).bind("blur", function(event) {
	if (jQuery.browser.mozilla == true) {
	//alert(1);
		clearTimeout(_section_header.animate.fade_id_t);
		clearTimeout(_section_header.animate.fade_out_t);
	}
});

jQuery(window).bind("focus", function(event) {
		if (jQuery.browser.mozilla == true) {
				_section_header.animate.section_fade_through ();
	}
});
*/
//_section_header.animate.start_fades ();
//var loop_t = setTimeout("start_fades ()",change_interval);


</script>
<script type="text/javascript">
$(document).ready(function(){ 
	$("#section_header").show("slow");
});
</script>
<?php } else { ?>
<script type="text/javascript">

$(document).ready(function(){ 
	$("#section_header").show("slow");
});



</script>


<?php }  ?>


<div style="display:none" id=section_header class="r_3_25 w_12_25 h_3_5">
<?php
global $area;
global $section;
$module="modules/section_header/templates";


$main_dir = "{$module}/main";
$area_dir = "{$module}/{$area}/main";
$section_dir = "{$module}/{$area}/{$section}";
if (! is_dir("{$section_dir}/images/banner")) {
    mkdir ("{$section_dir}/images/banner", 0, true);
    copy("modules/section_header/templates/default_section_header.jpg","{$section_dir}/images/banner/default.jpg");
}

if (!file_exists("{$section_dir}/images/arrow_1.png")) {
    copy("modules/section_header/templates/default_arrow_1.png","{$section_dir}/images/arrow_1.png");
    copy("modules/section_header/templates/default_arrow_2.png","{$section_dir}/images/arrow_2.png");
}

if (is_dir($section_dir)) {
	$template = $section_dir;
	$real_section = $section;
}
else if (is_dir($area_dir)) {
	$template = $area_dir;
	$real_section = "main";
} else {
	$template = $main_dir;
	$real_section = "main";
}

$images = "/{$template}/images";

$banner_text_file = "/{$template}/banner.txt";
if (file_exists($banner_text_file)) $banner_text =  file_get_contents($banner_text_file);
else $banner_text = $section;
if ($banner_text == "main") $banner_text = $area;
$banner_text = ucwords(str_replace("_", " ", $banner_text));

$info_text_file = "{$template}/images/banner/text.html";
if (file_exists($info_text_file)) $info_text =  file_get_contents($info_text_file);
else $info_text = <<<STOP
   
<h4>Find a course to<br>
  suit you...</h4>  
<p>Getting the right qualifications could make all the difference and will definitely have a big influence on how successful you can be in your career</p>
STOP;



$directory = "{$_SERVER["DOCUMENT_ROOT"]}{$images}/banner";
$pic_types = array("jpg", "jpeg", "gif", "png");
    
   // create a handler to the directory
    $dirhandler = opendir($directory);
 
    // read all the files from directory
    $nofiles=0;
    while ($file = readdir($dirhandler)) {
        if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types)) {
            $files[$nofiles]=$file;
            $text = substr ($file,0,strpos($file,".")) . ".html";
            if (file_exists ($text_file)) {
                $text[$nofiles] = file_get_contents($text_file);
            }
            $nofiles++;
        }  
    }
    shuffle ($files);
    $i = rand(0,count($files)-1);

    $image_count = 0;
    echo "<div id=rotator xx=1 style=display:none><ul>";
    foreach ($files as $img=>$value) {
    	$src = "{$images}/banner/{$value}";
    	//if ($image_count == $i) $visi_class = "opaque_100";
    	//else $visi_class = "opaque_0";
    	echo<<<STOP
    	<li><img id=section_header_image_{$image_count} 
    	class="section_header_image {$visi_class}"
    	src="{$src}"
    	
    	>
STOP;
    	$image_count++;
    }
    echo "</ul></div>";

    
$plain_text = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", strip_tags($info_text));

if ((isset($_SESSION["username"]))||($plain_text != "")) {
echo <<<STOP
 <div style="z-index:501" id="{$real_section}_info_arrow" class="r_1_25 c_9"><img src="{$images}/arrow_1.png">
    <div id="{$real_section}_info" class="c_1_25">{$info_text}
    </div> 
 </div>
STOP;
}

    
echo <<<STOP
 <h3 style="z-index:501" id=section_banner class="{$real_section}_banner">{$banner_text}<img   class="section_head_arrow" src="{$images}/arrow_2.png"></h3>
</div>
STOP;
 
?>

<?php if (isset($_SESSION["username"])) { ?>
<div id="section_head_image_area"></div>
<script type="text/javascript">
    
 if (typeof htmlView == "undefined") $.ajax({ url: "/modules/htmlView/htmlView.js", dataType: "script", async: false});
_info_htmlView = new htmlView ("<?php echo $real_section;?>_info",150,152,function () { $("#<?php echo $real_section;?>_info").attr("save_required",'true');  });   

 _section_header.edit.initialize();
 var html =  "<div style=\"position:absolute\">"
            + "<button id=\"btn_next_section_header\" onclick=\"_section_header.edit.next()\">Next &rarr;</button>" 
            + "<button id=\"btn_save_section_header\" onclick=\"_section_header.edit.save()\">Save</button>"
            + "</div>"
           
        
$("#section_header").append(html);

$("#section_header img").click (function () {_section_header.edit.initialize_image();});

</script>
    
<?php } ?>

